<?php

namespace Modules\System\Providers;

use Catch\Events\ReportException;
use Catch\Providers\CatchModuleServiceProvider;
use Modules\Common\Events\UploadedEvent;
use Modules\System\Console\AsyncTask;
use Modules\System\Console\ConnectorFrequencyWarning;
use Modules\System\Console\ConnectorLogRecord;
use Modules\System\Console\StatisticsConnectorLog;
use Modules\System\Events\ConnectorLogEvent;
use Modules\System\Listeners\ConnectorLogListener;
use Modules\System\Listeners\ReportExceptionListener;
use Modules\System\Listeners\UploadedListener;
use Modules\System\Support\Configure;

class SystemServiceProvider extends CatchModuleServiceProvider
{
    protected array $commands = [
        AsyncTask::class, // 异步任务
        ConnectorLogRecord::class, // 接口日志消费任务
        ConnectorFrequencyWarning::class, // 接口告警通知
        StatisticsConnectorLog::class, // 接口日志统计
    ];

    protected array $events = [
        // 异常监听
        ReportException::class => ReportExceptionListener::class,
        // 上传成功事件监听
        UploadedEvent::class => UploadedListener::class,
        // 接口日志记录
        // ConnectorLogEvent::class => ConnectorLogListener::class,
    ];

    public function boot(): void
    {
        // 加载动态配置到 Laravel 系统的 Config 中
        (new Configure)->loadToLaravelConfig($this->app->make('config'));
        // 开启接口日志记录
        if (config('catch.system_api_log')) {
            $this->events[ConnectorLogEvent::class] = ConnectorLogListener::class;
        }
    }

    /**
     * route path
     */
    public function moduleName(): string
    {
        // TODO: Implement path() method.
        return 'system';
    }

    public function configPath(): string
    {
        return parent::configPath(); // TODO: Change the autogenerated stub
    }
}
